package com.codingman.jpademo3;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class Demo2 {
	public static void main(String[] args) {
		EntityManagerFactory emf = Persistence.createEntityManagerFactory("employee_unit");
		EntityManager em = emf.createEntityManager();

		em.getTransaction().begin();
		
		Employee2 d2 = new Employee2(102, "Bob", 200.00);
		
		Address a2 = new Address(2, "Shenzhen", "China");
		Address a3 = new Address(3, "Shenzhen", "China");
		List<Address> adds = new ArrayList<Address>();
		adds.add(a2);
		adds.add(a3);
		d2.setAddress(adds);
				
		em.persist(d2);

		em.getTransaction().commit();

		em.close();
		emf.close();
	}
}
